import java.awt.Dimension;
import java.awt.TextField;

public class JAPI_Textfield extends TextField
{
	private static final long serialVersionUID = 3673790809546743330L;
	
	int w=0,h=0;

	public JAPI_Textfield (int w)
	{
		super(w);
	}

	public void setSize(int dw, int dh)
	{
		w = dw>0 ? dw : 0;
		h = dh>0 ? dh : 0;
		super.setSize(w,h);
	}

	public void setColumns(int c)
	{
		if((w=getPreferredSize(c).width)>0)
			super.setSize(w,h);
	}

	public int getColumns()
	{
		int c=0;
		while(getPreferredSize(c).width < getSize().width)
			c++;
		return(--c);
	}

	public Dimension getPreferredSize()
	{
		Dimension dim = super.getPreferredSize();
		dim.width  = w>0 ? w : dim.width;
		dim.height = h>0 ? h : dim.height;
		return(dim);
	}

	public Dimension getMinimumSize()
	{
		Dimension dim = super.getMinimumSize();
		dim.width  = w>0 ? w : dim.width;
		dim.height = h>0 ? h : dim.height;
		return(dim);
	}

}